package com.cuckoo.mall.thus.menuindex;

import android.content.Context;

import com.bgn.baseframe.base.BasePresenterImpl;
import com.bgn.baseframe.network.HttpObserver;
import com.bgn.baseframe.network.bean.TDataBean;
import com.bgn.baseframe.utils.UiUtil;
import com.cuckoo.mall.R;
import com.cuckoo.mall.javabean.Category;
import com.cuckoo.mall.network.ApiManager;

import java.util.List;


/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class MenuIndexPresenter extends BasePresenterImpl<MenuIndexContract.View> implements MenuIndexContract.Presenter {

    @Override
    public void loadAllCategorys() {
        ApiManager.getAllCategories().subscribe(new HttpObserver<TDataBean<List<Category>>>(mView) {
            @Override
            public void onSucceed(TDataBean<List<Category>> value) {
                if (value.getData() != null) {
                    mView.whenGetCategorysSucceed(value.getData());
                }
            }

            @Override
            public void onDefeat(TDataBean<List<Category>> value) {
                super.onDefeat(value);
                mView.whenGetCategorysFaild(value.getError_msg());
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mView.whenGetCategorysFaild(UiUtil.getString(R.string.server_error));
            }
        });

    }
}
